// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import "babel-polyfill";
import Vue from 'vue';
import App from './App.vue';
import Meta from 'vue-meta'; //设置页面meta信息
Vue.use(Meta);
import router from './router'; //引入路由
import store from './store'; //引入vuex
import axios from './utils/axios'; //引入axios
Vue.prototype.axios = axios;
window.axios = axios;
import NProgress from 'nprogress'; //路由进度条
import 'nprogress/nprogress.css'; //路由进度条样式
import ElementUI from './element/index' //按需引入element-ui
Vue.prototype.$ELEMENT = {
	size: 'small'
}; //element-ui默认尺寸控制
Vue.use(ElementUI);
import '@/styles/common.scss'; // 引入公用css重置
Vue.config.productionTip = false; //关闭提示
//路由跳转前置事件
router.beforeEach((to, from, next) => {
	NProgress.start();
	if (to.matched.length === 0) { //如果未匹配到路由
		let lastPath = sessionStorage.getItem("lastPath");
		lastPath ? next(lastPath) : next('/')
		// from.path ? next({
		//   path: from.path
		// }) : next('/'); //如果上级也未匹配到路由则跳转主页面，如果上级能匹配到则转上级路由
	} else {
		if (to.meta.metaInfo) {
			store.commit("CAHNGE_META_INFO", to.meta.metaInfo)
		}else{
			store.commit("CAHNGE_META_INFO", "微服务开发平台")
		}
		sessionStorage.setItem("lastPath", from.fullPath); //存储跳转之前的路由
		if (to.path != "/layout/homepage" && !to.query.appId && from && from.query.appId) { //增加参数appId
			to.query.appId = from.query.appId
			next(to)
		} else {
			next()
		}
	}
});
//路由跳转后置事件
router.afterEach(transition => {
	NProgress.done();
});
new Vue({
	el: '#app',
	router,
	data: {
		eventHub: new Vue() //兄弟组件传值代理
	},
	store, //注册上vuex的store: 所有组件对象都多一个属性$store
	metaInfo() {
		return {
			title: store.state.metaInfo.title ? store.state.metaInfo.title : "开发公司统一门户", //页面标题(支持动态控制)
			meta: [{ //双核浏览器启用谷歌内核
				name: "renderer",
				content: "webkit"
			}, {
				"http-equiv": "X-UA-Compatible",
				content: "IE=EmulateIE11" //ie启用标准模式
			}]
		}
	},
	render: h => h(App)
});
